#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

char buff[1000];
bool occur[20000];
int v[20000];

int main(int argc, char* argv[]) {
  int count = 0;
  int n = argc - 2;
  for (int i = 0; i < n; ++i) v[i] = atoi(argv[i+2]);
  freopen(argv[1], "r", stdin);
  while (fgets(buff, 1000, stdin) != NULL) {
    int pos = 0, delta;
    int x;
    memset(occur, false, sizeof(occur));
    while (sscanf(buff+pos, "%d%n", &x, &delta) != EOF) {
      pos += delta;
      occur[x] = true;
    }
    bool flag = true;
    for (int i = 0; i < n; ++i) if (!occur[v[i]]) flag = false;
    if (flag) ++count;
  }
  printf("%d\n", count);
  return 0;
}
